#    This is part of WeatherFront.
#
#    Copyright (C) 2010 Stefan Sieber
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#


#import modules required by application
import PyFR.Appliance
import PyFR.WaitController
import PyFR.Debugging
import PyFR.OptionDialog
import PyFR.FileBrowser
import PyFR.MenuController
import PyFR.AppLauncherController
import Foundation

from WeatherFrontMetaData import *
from WeatherFrontWeatherAPI import *


verbose=1
def log(s,level=1):
	if verbose >= level:
		Foundation.NSLog( u"%s: %@", "WeatherFrontLog", s ) 
	pass

class WFMenuController(PyFR.MenuController.MenuController):


	def GetItemMetadata(self, controller, item):
		log(u"WFMenuController::GetItemMetadata for %s" % str(item))
		ret=WeatherFrontPreviewMetadataController.alloc().initWithItem_(item)
		return ret
	
	def UpdateMainMenu(self, controller, channel):
		log("WFMenuController::UpdateMainMenu")
		return 0
		
		
	def MakeMainMenu(self):
		root=PyFR.MenuController.Menu("WeatherFront", [])
		items=WeatherAPI.GetWeatherItems()
		for item in items:
			chstr=item.GetName()
			item=PyFR.MenuController.MenuItem(chstr, self.UpdateMainMenu, item, self.GetItemMetadata, False)
			root.AddItem(item)
		return root
		

	def init(self):
		log("WFMenuController::init")
		self.MainMenu=self.MakeMainMenu()
		ac=PyFR.MenuController.MenuController.initWithMenu_(self,self.MainMenu)
		return ac

class RUIWeatherFrontAppliance( PyFR.Appliance.Appliance ):
	def getController(self):
		wfmc=WFMenuController.alloc()
		ret = wfmc.init()
		return ret






